package com.generate.tools.service;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.generate.tools.constrant.Constrant;
import com.generate.tools.utils.PropertiesUtil;

public class AbstractConnection {
	
	public static final String PRO = Constrant.SUFFIX;
	
	public Connection getConn() {
		String driver = PropertiesUtil.read("jdbc_driver", Constrant.MYSQL+PRO);
		// URL指向要访问的数据库名scutcs
		String url = PropertiesUtil.read("jdbc_url", Constrant.MYSQL+PRO);
		// MySQL配置时的用户名
		String user = PropertiesUtil.read("jdbc_username", Constrant.MYSQL+PRO);
		// Java连接MySQL配置时的密码
		String password =  PropertiesUtil.read("jdbc_password", Constrant.MYSQL+PRO);

		try {
			Class.forName(driver);
			// 连续数据库
			Connection conn = DriverManager.getConnection(url, user, password);
			return conn;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
